package com.leetcode.algorithm.y22.todo;

/**
 * 480. 滑动窗口中位数
 * 
 * https://leetcode.cn/problems/sliding-window-median/
 * 
 * @author jie.deng
 *
 */
class Question0480Solution01 {

	public double[] medianSlidingWindow(int[] nums, int k) {
		double[] medianArr = new double[nums.length - k + 1];
		int len = medianArr.length;
		int gap = k >> 1;
		if ((k & 1) == 0) {
			for (int i = 0; i < len; i++) {
				medianArr[i] = nums[i + gap];
			}
		} else {
			for (int i = 0; i < len; i++) {
				int sum = nums[i + gap] + nums[i + gap + 1];
				medianArr[i] = (double) sum / 2;
			}
		}
		return medianArr;
	}

}